package cc.ls51.modules.SysRole.service.impl;

import cc.ls51.common.PageUtils;
import cc.ls51.common.Query;
import cc.ls51.form.SysRoleListForm;
import cc.ls51.modules.SysRole.entity.SysRole;
import cc.ls51.modules.SysRole.mapper.SysRoleMapper;
import cc.ls51.modules.SysRole.service.ISysRoleService;
import cc.ls51.modules.SysUser.entity.SysUser;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author llf
 * @since 2019-09-02
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Autowired
    SysRoleMapper sysRoleMapper;

    @Override
    public PageUtils<SysRole> getPage(SysRoleListForm form) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if(StrUtil.isNotEmpty(form.getRoleName())){
            queryWrapper.likeRight("role_name",form.getRoleName());
        }
        queryWrapper.orderByDesc("id");
        IPage<SysRole> page = sysRoleMapper.selectPage(
                new Query<SysRole>().getPage(form.getPageNumber(),form.getPageSize()),
                queryWrapper
        );
        return new PageUtils<>(page);
    }
}
